<?php
    function SDL(?string $str):int{ return strlen(iconv("UTF-8","GB2312//IGNORE",$str)); }

    function printTable($name,$v1)
    {
        $totWidth=1;
        foreach($v1 as $k2=>$v2)
            if(is_string($k2))
                $totWidth+=max(SDL($k2),SDL($v2))+3;
        echo '|';
        for($i=0;$i<($totWidth-SDL($name))/2;++$i) echo '-';
        echo $name;
        for($i=0;$i<($totWidth-SDL($name))/2;++$i) echo '-';
        echo '|';
        echo "\n";
        echo '|';
        foreach($v1 as $k2=>$v2)
            if(is_string($k2))
            {
                echo ' ';
                for($i=0;$i<(max(SDL($k2),SDL($v2))-SDL($k2))/2;++$i) echo ' ';
                echo $k2;
                for($i=0;$i<(max(SDL($k2),SDL($v2))-SDL($k2))/2;++$i) echo ' ';
                echo ' |';
            }
        echo "\n";
        echo '|';
        foreach($v1 as $k2=>$v2)
            if(is_string($k2))
            {
                echo ' ';
                for($i=0;$i<(max(SDL($k2),SDL($v2))-SDL($v2))/2;++$i) echo ' ';
                echo $v2;
                for($i=0;$i<(max(SDL($k2),SDL($v2))-SDL($v2))/2;++$i) echo ' ';
                echo ' |';
            }
        echo "\n";
    }

    function printTables($name,$ans)
    {
        $totWidth=1;
        foreach($ans as $v1)
        {
            $totW=1;
            foreach($v1 as $k2=>$v2)
                if(is_string($k2))
                    $totW+=max(SDL($k2),SDL($v2))+3;
            $totWidth=max($totW,$totWidth);
        }
        echo '|';
        for($i=0;$i<($totWidth-SDL($name))/2;++$i) echo '-';
        echo $name;
        for($i=0;$i<($totWidth-SDL($name))/2;++$i) echo '-';
        echo '|';
        echo "\n";
        echo '|';
        foreach($ans as $k1=>$v1)
        {
            if($k1===0)
            {
                foreach($v1 as $k2=>$v2)
                    if(is_string($k2))
                    {
                        echo ' ';
                        for($i=0;$i<(max(SDL($k2),SDL($v2))-SDL($k2))/2;++$i) echo ' ';
                        echo $k2;
                        for($i=0;$i<(max(SDL($k2),SDL($v2))-SDL($k2))/2;++$i) echo ' ';
                        echo ' |';
                    }
                echo "\n";
            }
            echo '|';
            foreach($v1 as $k2=>$v2)
                if(is_string($k2))
                {
                    echo ' ';
                    for($i=0;$i<(max(SDL($k2),SDL($v2))-SDL($v2))/2;++$i) echo ' ';
                    echo $v2;
                    for($i=0;$i<(max(SDL($k2),SDL($v2))-SDL($v2))/2;++$i) echo ' ';
                    echo ' |';
                }
            echo "\n";
        }
    }

    function printHtmlTable($v1)
    {
        $s='<table border="1" cellspacing="0" width="100%">';
        $s.='<tr>';
        foreach($v1 as $k2=>$v2)
            if(is_string($k2))
                $s.='<td>'.$k2.'</td>';
        $s.='</tr>';
        $s.='<tr>';
        foreach($v1 as $k2=>$v2)
            if(is_string($k2))
                $s.='<td>'.$v2.'</td>';
        $s.='</tr>';
        $s.='</table>';
        return $s;
    }

    function printHtmlTables($ans)
    {
        $s='<table border="1" cellspacing="0" width="100%">';
        $s.='<tr>';
        foreach(reset($ans) as $k2=>$v2)
            if(is_string($k2))
                $s.='<td>'.$k2.'</td>';
        $s.='</tr>';
        foreach($ans as $v1)
        {
            $s.='<tr>';
            foreach($v1 as $k2=>$v2)
                if(is_string($k2))
                    $s.='<td>'.$v2.'</td>';
            $s.='</tr>';
        }
        $s.='</table>';
        return $s;
    }